#include<stdlib.h>
#include <stdio.h>
#include <unistd.h>

extern char ** environ;

char* const addenv[]=
{
    (char* const)"myenv1=1234",
    (char* const)"myenv2=1234",
    (char* const)"myenv3=1234",
    (char* const)"myenv4=1234",
    (char* const)"myenv5=1234",
    NULL
};

int main()
{
    printf("程序替换前\n");
    //替换命令
    //execl("/usr/bin/ls","/usr/bin/ls", "-la", "-ln", NULL);
    //不携带路径
    //execlp("ls","ls","-a","-l", NULL);
    //命令行参数以vector的形式
    //execv("/usr/bin/ls",argv);
    char* const argv[]=
    {
       (char* const)"-a",
       (char* const)"-l",
       (char* const)"-ln",
       NULL 
    };
    int i = 0;
    for(; addenv[i]; i++)
    {
        putenv(addenv[i]);
    }
    //不需携带路径和命令行参数
    execvpe("./oother",argv,environ);
    char** e = environ;
    for(;*e; *e++)
    {
        printf("%s\n", *e);
    }
    //execl("/usr/bin/ls","ls", "-la", "-ln", NULL);
    
    //替换自己写的程序 
    //execl("/usr/bin/python3","python","other.py", NULL);
    //execl("/usr/bin/bash","bash","other.sh", NULL);
    //execl("./other","other", NULL);
    //printf("程序替后\n");
    return 0;
}
